#include<deque>
class MyStack {
private:
    std::deque<int> queue[2];
    int which = 0;

public:
    /** Initialize your data structure here. */
    MyStack() {

    }

    /** Push element x onto stack. */
    void push(int x) {
        queue[which].push_back(x);
    }

    /** Removes the element on top of the stack and returns that element. */
    int pop() {
        while (queue[which].size() != 1) {
            queue[1 - which].push_back(queue[which].front());
            queue[which].pop_front();
        }
        int res = queue[which].front();
        queue[which].pop_front();
        which = 1 - which;
        return res;
    }

    /** Get the top element. */
    int top() {
        while (queue[which].size() != 1) {
            queue[1 - which].push_back(queue[which].front());
            queue[which].pop_front();
        }
        int res = queue[which].front();
        queue[which].pop_front();
        queue[1-which].push_back(res);
        which = 1 - which;
        return res;
    }

    /** Returns whether the stack is empty. */
    bool empty() {
        return queue[which].empty();
    }
};

/**
 * Your MyStack object will be instantiated and called as such:
 * MyStack* obj = new MyStack();
 * obj->push(x);
 * int param_2 = obj->pop();
 * int param_3 = obj->top();
 * bool param_4 = obj->empty();
 */